<script lang="ts" setup>
import { LockStatus, OnlineStatus } from '@/types/enum'
import { bikeLocationDataType } from '@/api/bike/types/bike'
import LockStatusImg from '@/assets/map/viewRegional/lockstatus.png'
import LineStatusImg from '@/assets/map/viewRegional/linestatus.png'
import PowerLevelImg from '@/assets/map/viewRegional/powerlevel.png'
import VoltageImg from '@/assets/map/viewRegional/voltage.png'
import { ref } from 'vue'
import { inject } from 'vue'
import { ElMessage } from 'element-plus'
defineProps<{
  data: bikeLocationDataType[]
}>()
const changeLockStatus = (data: LockStatus | null) => {
  switch (data) {
    case LockStatus.Locked:
      return '上锁'
    case LockStatus.Unlocked:
      return '开锁'
    default:
      return ''
  }
}
const changeBikeOnlineStatus = (data: OnlineStatus | null) => {
  switch (data) {
    case OnlineStatus.UnOnLine:
      return '断网'
    case OnlineStatus.OnLine:
      return '联网'
    default:
      return ''
  }
}
const hover = ref<boolean>(false)
const handleCloseMouseTool = inject<() => void>('handleCloseMouseTool', () => {
  ElMessage.warning('关闭鼠标工具失败')
  throw new Error('handleCloseMouseTool 关闭鼠标工具失败')
})
const handleClose = () => {
  handleCloseMouseTool()
}
</script>

<template>
  <div class="view-regional">
    <header class="view-regional__header">
      <span>查看区域内车辆({{ data.length }}辆)</span>
      <el-icon
        @click="handleClose"
        absolute
        top-5
        right-5
        cursor-pointer
        @mouseover="hover = true"
        @mouseout="hover = false"
        :color="hover ? 'var(--xy-primary-color)' : 'var(--xy-normal-text-color)'"
        size="20"
      >
        <Close />
      </el-icon>
    </header>
    <div class="view-regional__body">
      <el-scrollbar height="500px">
        <div v-for="bike in data" :key="bike.bikeId" flex flex-col class="view-regional__item">
          <div mb-10>
            车辆编号: <span>{{ bike.bikeCode }}</span>
          </div>
          <div grid grid-rows-1 grid-cols-4 gap-x-25>
            <div flex items-center>
              <img :src="LockStatusImg" alt="" />
              <span ml-5>{{ changeLockStatus(bike.lockStatus) }}</span>
            </div>
            <div flex items-center>
              <img :src="LineStatusImg" alt="" />
              <span ml-5>{{ changeBikeOnlineStatus(bike.bikeOnlineStatus) }}</span>
            </div>
            <div flex items-center>
              <img :src="PowerLevelImg" alt="" />
              <span ml-5>{{ bike.powerLevel }}%</span>
            </div>
            <div flex items-center>
              <img :src="VoltageImg" alt="" />
              <span ml-5>{{ bike.inputVoltage }}</span>
            </div>
          </div>
        </div>
      </el-scrollbar>
    </div>
  </div>
</template>

<style scoped lang="scss">
.view-regional {
  position: absolute;
  right: 20px;
  top: 100px;
  z-index: 200;
  background: #ffffff;
  border-radius: 10px 10px 10px 10px;

  &__header {
    font-weight: 500;
    font-size: 18px;
    color: #333333;
    line-height: 28px;
    text-align: center;
    padding: 20px;
    position: relative;
  }
  &__body {
    padding: 0 10px 20px 10px;
  }
  .view-regional__item + .view-regional__item {
    margin-top: 20px;
  }
}
</style>
